package com.fr.schedule.dao;

import com.fr.base.ReflectionUtils;
import com.fr.schedule.ScheduleContext;

public class IdFieldMapper extends FieldMapper
{
  private Class fieldClazz;

  public IdFieldMapper(Class paramClass, String paramString1, int paramInt, String paramString2)
  {
    super(paramString1, paramInt, paramString2);
    this.fieldClazz = paramClass;
    if ((paramInt != -5) && (paramInt != 4))
      throw new IllegalArgumentException("The type must be java.sql.Types.BIGINT or java.sql.Types.INTEGER !");
  }

  public void setFieldClazz(Class paramClass)
  {
    this.fieldClazz = paramClass;
  }

  public Class getFieldClazz()
  {
    return this.fieldClazz;
  }

  public Object id2Field(long paramLong)
  {
    return ScheduleContext.getJdbcDaoManager().load(this.fieldClazz, paramLong);
  }

  public long field2Id(Object paramObject)
  {
    if (paramObject == null)
      return -1L;
    ScheduleContext.getJdbcDaoManager().saveOrUpdate(paramObject);
    return ((Number)ReflectionUtils.getPrivateFieldValue(paramObject, "id")).longValue();
  }

  public void delete(Object paramObject)
  {
    if (paramObject == null)
      return;
    ScheduleContext.getJdbcDaoManager().delete(paramObject);
  }
}